#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : gtmsAutoTestProject 
@File    : pos_manage_api.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/4/26 17:50 
@Describe:
"""
from Comm.tools.toolsControl import ToolsHandler
from APIs.middleApi.base_middle_api import BaseMiddleApi


class PosManageAPI(BaseMiddleApi):
    def __init__(self, environment):
        super().__init__(environment)

    def pos_device_manage_page(self, brandCode, deviceMac='14:5A:FC:22:CC:1D', pageNum='1', pageSize='100'):
        """
        设备管理分页
        :param brandCode: 品牌编码
        :param deviceMac: 设备MAC地址
        :param pageNum: 第几页，默认1
        :param pageSize: 每页展示几条，默认100
        :return:
        """
        payload = '{"pageNum":"' + pageNum + '","pageSize":"' + pageSize + '","brandCode":"' + brandCode + '","deviceMac":"' + deviceMac + '"}'
        response = self.http_requests('catering-backend/pos/device/manage/page', payload)
        return response

    def shop_application_event_insert(self, brandCode, eventType='21', applicationName='printer-api'):
        """
        推送门店应用事件
        :param brandCode:品牌编码
        :param eventType: 应用类型: 21-重启
        :param applicationName: 服务名称：pos-api ， printer-api
        :return:
        """
        shopCode = ToolsHandler.get_shopCode(brandCode)
        now_time = ToolsHandler.get_now_time()  # 当前时间
        payload = '{"brandCode":"' + brandCode + '","applicationName":"' + applicationName + '","eventType":"' + eventType + '","targetVersion":"","shopCodes":["' + shopCode + '"],"executeTime":"' + now_time + '"}'
        response = self.http_requests('shop-steward-backend/shopApplicationEvent/insert', payload)
        return response

    def pos_derive_update_status(self, deriveId, brandCode, deviceStatus='0'):
        """
        更新设备状态
        :param brandCode: 品牌编码
        :param deriveId: 设备ID,通过设备管理分页接口获取
        :param deviceStatus: 设备状态: 0-关闭，1-开启
        :return:
        """
        payload = '{"brandCode":"' + brandCode + '","deviceStatus":"' + deviceStatus + '","id":"' + deriveId + '"}'
        response = self.http_requests('catering-backend/pos/device/manage/updateStatusById', payload)
        return response

    def pos_device_manage_dicList_deviceBrand(self):
        """
        获取设备品牌字典
        :return:
        """
        payload = '{}'
        response = self.http_requests('catering-backend/pos/device/manage/dicList/deviceBrand', payload)
        return response

    def pos_printer_manage_printerTypeDic(self):
        """
        打印机类型字典列表
        :return:
        """
        payload = '{}'
        response = self.http_requests('catering-backend/pos/printer/manage/printerTypeDic', payload)
        return response

    def pos_device_manage_save(self, brandCode, shopCode, deviceBrandCode, deviceName, deviceMac, printerIp, deviceStatus, cashCode, printerTypeCode, deviceBrandName):
        """
        POS设备新增
        :param brandCode: 品牌编码
        :param shopCode: 门店编码
        :param deviceBrandCode: 设备品牌编码
        :param deviceName: 设备名称
        :param deviceMac: 设备mac地址
        :param printerIp: ip地址
        :param deviceStatus: 设备状态(0-禁用 1-启用)
        :param cashCode: 收银机号
        :param printerTypeCode: 打印机型号名称编码
        :param deviceBrandName: 设备品牌名称
        :return:
        """
        payload = '{"printerMode":"3","brandCode":"' + brandCode + '","shopCode":"' + shopCode + '","deviceBrandCode":"' + deviceBrandCode + '","deviceName":"' + deviceName + '","deviceMac":"' + deviceMac + '","printerIp":"' + printerIp + '","deviceType":"1","deviceStatus":"' + deviceStatus + '","cashCode":"' + cashCode + '","printerTypeCode":"' + printerTypeCode + '","receiptPrint":"11111111","deviceBrandName":"' + deviceBrandName + '","softwareVersion":"V20200204-01"}'
        response = self.http_requests('catering-backend/pos/device/manage/save', payload.encode('utf-8'))
        return response


if __name__ == '__main__':
    test = PosManageAPI('sit')
    test.pos_device_manage_dicList_deviceBrand()
